package com.efei.test.jdbc.dao;


import com.efei.test.jdbc.entity.UserInfoEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * 单表操作
 */
public interface UserInfoRepository extends PagingAndSortingRepository<UserInfoEntity, Integer> {

    List<UserInfoEntity> findByName(String ame);

    @Modifying
    @Query("update test_user set age=:age where name = :name")
    Boolean updateAgeById(String name,Integer age);

    @Modifying
    @Query("delete from test_user where id = :id")
    Boolean deleteRecord(Integer id);

    /**
     * 分页查询，这种可能不支持，估计需要自己写S分页QL
     */
//    @Query("select * from test_user order id asc")
//    Page<UserInfo> findList(Pageable pageable);

    /**
     * 分页查询
     * @param age
     * @param pageable
     * @return
     */
    Page<UserInfoEntity> findByAgeAfterOrderByIdDesc(Long age, Pageable pageable);


}
